<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css"></style>
</head>
<body>
    <h1>同步与异步</h1>
    <button onclick="load(false)">同步加载</button>
    <button onclick="load(true)">异步加载</button>
    <hr>

    <script>

        function load(b) {
            var msg = '我是来自于JS的值';

            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
                if (xhr.status == 200 && xhr.readyState == 4) {
                    msg = xhr.responseText;
                    console.log(msg);
                }
            }
            xhr.open('get', './php/6.php', b);
            xhr.send();

            alert(msg);
        }
    
    </script>
</body>
</html>
